package com.windward.vii.dao.mapper;

import com.windward.vii.dao.entity.UserAttention;
import com.windward.vii.dao.entity.UserAttentionKey;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface UserAttentionMapper {
    @Delete({
        "delete from user_attention",
        "where uid = #{uid,jdbcType=BIGINT}",
          "and attention_uid = #{attentionUid,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(UserAttentionKey key);

    @Insert({
        "insert into user_attention (uid, attention_uid, ",
        "status, create_time)",
        "values (#{uid,jdbcType=BIGINT}, #{attentionUid,jdbcType=BIGINT}, ",
        "#{status,jdbcType=TINYINT}, #{createTime,jdbcType=TIMESTAMP})"
    })
    int insert(UserAttention record);

    int insertSelective(UserAttention record);

    @Select({
        "select",
        "uid, attention_uid, status, create_time",
        "from user_attention",
        "where uid = #{uid,jdbcType=BIGINT}",
          "and attention_uid = #{attentionUid,jdbcType=BIGINT}"
    })
    @ResultMap("BaseResultMap")
    UserAttention selectByPrimaryKey(UserAttentionKey key);

    int updateByPrimaryKeySelective(UserAttention record);

    @Update({
        "update user_attention",
        "set status = #{status,jdbcType=TINYINT},",
          "create_time = #{createTime,jdbcType=TIMESTAMP}",
        "where uid = #{uid,jdbcType=BIGINT}",
          "and attention_uid = #{attentionUid,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(UserAttention record);

    /***********以下为自定义方法************************/

    @Select({
            "select * ",
            "from user_attention",
            "where uid = #{uid,jdbcType=BIGINT} order by create_time desc"
    })
    @ResultMap("BaseResultMap")
    List<UserAttention> getAttentionListByUid(Long uid);

    @Select({
            "select * ",
            "from user_attention",
            "where attention_uid = #{uid,jdbcType=BIGINT} order by create_time desc"
    })
    @ResultMap("BaseResultMap")
    List<UserAttention> getFansListByUid(Long uid);

    @Select({
            "select count(attention_uid)",
            "from user_attention",
            "where uid = #{uid,jdbcType=BIGINT}"
    })
    int getAttentionCountByUid(Long uid);

    @Select({
            "select count(uid)",
            "from user_attention",
            "where attention_uid = #{attentionUid,jdbcType=BIGINT}"
    })
    int getFansCountByUid(Long attentionUid);
}